using UnityEngine;
using System.Collections;

public class AnimationScript : MonoBehaviour {

	public int fps;
	private float _fps;
	private float timer;
	public Texture2D[] frames;
	private int currentFrame;
	
	void Start ()
	{
		_fps = 1.0f/fps;
		currentFrame = 1;
		renderer.material.mainTexture = frames[0];
	}
	
	void Update ()
	{
		
		if (timer > 0.0)
				timer -= Time.deltaTime;
		
		if (timer <= 0.0)
				timer = 0.0f;
		
		if (timer == 0.0)
				NextFrame();
	}
	
	
	public void NextFrame()
	{
		
		if (currentFrame < frames.Length)
			currentFrame ++;
		
		else 
			currentFrame = 1;
		renderer.material.mainTexture = frames[currentFrame - 1];
		timer = _fps;
		
		
	}
}
